<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0" />
    <title>沃闪购</title>
    <link rel="icon" href="../img/bitbug_favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../css/normalize.css" />
    <!--<link rel="stylesheet" href="index.css"/>-->
    <!--<link rel="stylesheet" href="../index.css"/>-->
    <link rel="stylesheet" href="../index_format.css" />
    <link rel="stylesheet" href="../css/layer.css" />

    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/rem.js"></script>
    <script type="text/javascript" src="../js/tool.js"></script>
    <script>
        document.documentElement.style.height = window.innerHeight + 'px';
    </script>
</head>

<body onload="preventMove()">
    <div class="header">
        <div><img src="../img/wo-logo.png" alt="" /></div>
        <div class="wo-topic t-r">商户注册</div>
    </div>
    <div class="container ">
        <div class="flex-box">
            <div class="choose-register ">
                <form id="registerForm" action="">
                    <ul class="form-list">
                        <li><label for="wo_phone">手机号：</label><input id="wo_phone" name="mobile" type="text" value="" placeholder="请输入手机号" autofocus/></li>
                        <li><label for="wo_phone">短信验证码：</label><input id="wo_code" name="code" type="text" value="" placeholder="验证码" /><input id="get_code" type="button" value="获取短信验证码" /></li>
                        <!-- <li><label for="wo_name">&nbsp;&nbsp;姓&nbsp;&nbsp;名：</label><input id="wo_name" name="name" type="text" value="" placeholder="请输入姓名（可选）" /></li>
                        <li><label for="wo_identify">&nbsp;&nbsp;身份证：</label><input id="wo_identify" name="card" type="text" value="" placeholder="请输入身份证号（可选）" /></li> -->
                        <li><label for="wo_pwd">密&nbsp;&nbsp;码：</label><input id="wo_pwd" name="password" type="password" placeholder="请输入6位以上密码" value="" />
                        </li>
                        <li><label for="wo_pwd2">确认密码：</label><input id="wo_pwd2" name="password_2" type="password" value="" placeholder="请输入6位以上密码" />
                        </li>
                    </ul>
                </form>
                <div class="margin-center"></div>
                <div class="btn-group">
                    <!-- <a href="javascript:layer_cofirm('确认取消注册？');" class="btn-style">上一步</a> -->
                    <a id="reg_submit" href="javascript:;" class="btn-style"> 下一步</a>
                </div>
            </div>
            <!--<div class="register-info hide">-->
            <!--<p>恭喜您，注册成功！</p>-->

            <!--<div><a href="login.html" class="btn-style">返回登录界面</a></div>-->
            <!--</div>-->
        </div>
    </div>
    <script type="text/javascript" src="../js/layer.js"></script>
    <script>
        var rigisterPage = {
            wo_phone: '#wo_phone',
            wo_name: '#wo_name',
            wo_identify: '#wo_identify',
            wo_pwd: '#wo_pwd',
            wo_pwd2: '#wo_pwd2',
            reg_submit: '#reg_submit',
            //        register_info: '.register-info',
            choose_register: '.choose-register',
            get_code: '#get_code',
            host_server: getServerHost(),
            // url: '/api/shopping/merchantRegister',
            sendVerifyCode: '/api/shopping/sendVerifyCode?',
            checkVerifyCodeUrl: '/api/shopping/checkVerifyCode?',
            registerForm: "#registerForm",
            init: function() {
                this.reisgerPart();
                this.getCode();
            },
            registerCheck: function() {
                var context = this;
                //验证手机
                function testPhone() {
                    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
                    if (!myreg.test($(context.wo_phone).val())) {
                        layer_msg('请输入有效的手机号码！');
                        return false;
                    }
                    return true;
                }
                //验证身份证号
                function testIdentify() {
                    if ($(context.wo_name) || $(context.wo_identify)) {
                        // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
                        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                        if (reg.test($(context.wo_identify).val()) === false) {
                            layer_msg("姓名和身份证输入不合法");
                            return false;
                        } else {
                            return true;
                        }
                    } else {
                        return true;
                    }
                }

                function checkPassword(str) {
                    var reg2 = /([a-zA-Z0-9!@#$%^&*()_?<>{}]){6,18}/;
                    //                var reg3 = /[a-zA-Z]+/;
                    //                var reg4 = /[0-9]+/;
                    if (reg2.test(str)) {
                        return true;
                    } else if (!reg2.test(str)) {
                        layer_msg("密码长度在6-18位之间");
                        return false;
                    }
                    // else if (!reg3.test(str)) {
                    //                    alert("密码需含有字母");
                    //                    return false;
                    //                }
                    //                else if (!reg4.test(str)) {
                    //                    alert("密码需含有数字");
                    //                    return false;
                    //                }
                    else {
                        return true;
                    }
                }

                function testIdentify() {
                    if ($(context.wo_pwd).val() !== $(context.wo_pwd2).val()) {
                        layer_msg('两次的输入不一样');
                        return false;
                    } else if ($(context.wo_pwd).val() == "") {
                        layer_msg('请输入密码');
                        return false;
                    } else {
                        return true;
                    }
                }

                //            testPhone();
                //            testIdentify()
                //            checkPassword($('#wo_pwd').val());
                //            testIdeify();
                //            console.log(testPhone() && testIdentify()&& checkPassword($('#wo_pwd').val()) && testIdeify())
                return testPhone() && checkPassword($('#wo_pwd').val()) && testIdentify();
            },
            getCode: function() {
                var context = this;
                var wait = 60;
                //验证手机
                function testPhone() {
                    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
                    if (!myreg.test($(context.wo_phone).val())) {
                        layer_msg('请输入有效的手机号码！');
                        return false;
                    }
                    return true;
                }

                function time(o) {
                    console.log(o)
                    if (wait == 0) {
                        $(o).attr('disabled', false);
                        $(o).val('获取验证码');
                        wait = 60;
                    } else {
                        $(o).attr('disabled', true);
                        $(o).val(wait + "秒后重新发送");
                        wait--;
                        setTimeout(function() {
                            time(o)
                        }, 1000)
                    }
                }
                $(context.get_code).click(function(e) {
                    if (testPhone()) {
                        if (!$(context.get_code).isDisabled) {
                            time(context.get_code);
                            //context.checkPhone();
                            $.ajax({
                                type: 'POST',
                                // contentType: "application/json;charset=UTF-8",
                                data: 'phone=' + $(context.wo_phone).val(),
                                url: context.host_server + context.sendVerifyCode,
                                dataType: 'json',
                                success: function(response) {
                                    console.log(response);
                                    if (200 == response.code) {
                                        if (response.res) {
                                            layer_msg('验证码已发送等待接收')
                                        } else {
                                            layer_msg('验证码发送失败，请60s后重试');
                                        }
                                    } else if (999 == response.code) {
                                        layer_msg(response.msg);
                                    } else {

                                    }
                                    /*
                                    if (200 == response.code) {
                                        if (!response.res) {
                                            layer_msg('输入的验证码错误，请稍后再试');
                                        } else {
                                            layer_msg('验证码');
                                            $.ajax({
                                                type: 'POST',
                                                data: 'phone=' + formData.userName + "&password=" + formData.password,
                                                url: context.host_server + context.changePassword,
                                                dataType: 'json',
                                                success: function(response) {
                                                    console.log(response)
                                                    if (200 == response.code) {
                                                        layer_cofirm('改密成功，跳转到主页')
                                                    }
                                                },
                                                error: function() {}
                                            })
                                        }
                                    }
*/
                                },
                                error: function() {}
                            })
                        }
                    }
                });
            },
            //点击注册按钮提交数据
            reisgerPart: function() {
                var context = this;

                $(context.reg_submit).click(function(e) {
                    e.preventDefault();
                    var postData = {};
                    postData = $(context.registerForm).serializeArray();
                    // console.log(postData)
                    postData.pop();
                    //                postData.push({
                    //                    name: "channelName",
                    //                    value: sessionStorage.getItem('bes_com')
                    //                });
                    postData = arry2json(postData);
                    // console.log(postData)

                    console.log(context.registerCheck())
                    if (context.registerCheck()) {
                        var timer = setTimeout(function() {
                            $.ajax({
                                type: 'post',
                                url: context.host_server + context.checkVerifyCodeUrl,
                                data: "phone=" + postData.mobile + "&code=" + postData.code,
                                // contentType: "application/json;charset=UTF-8",
                                dataType: 'json',
                                success: function(response) {
                                    clearTimeout(timer);
                                    timer = null;
                                    if ('200' == response.code) {
                                        console.log(response);
                                        if (!response.res) {
                                            layer_msg('验证码存在错误，请重新填写');
                                        } else {
                                            layer_msg('继续下一步')
                                            $(context.registerForm)[0].reset();
                                            sessionStorage.setItem('postData', JSON.stringify(postData));
                                            location.href = "./bank_info.html"
                                        }
                                    } else if ('999' == response.code) {
                                        layer_msg(response.msg)

                                    } else {
                                        layer_msg('未知错误')
                                    }
                                },
                                error: function() {}
                            })
                        }, 1000)
                    } else {
                        //layer_msg(' 填写信息存在错误请重新填写');
                    }
                })
            }
        }


        function MyToggle(showObj, hideObj, time) {
            $(hideObj).fadeOut(0);
            $(showObj).fadeIn(time);
        }

        rigisterPage.init();
    </script>



</body>

</html>
